package com.lagou.controller;

import com.lagou.bean.Result;
import com.lagou.bean.UpLoadResult;
import com.lagou.service.OSSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author zjy
 */
@Controller
@RequestMapping("/oss")
public class OSSController {

    @Autowired
    private OSSService OSSService;

    @PostMapping("/upload")
    @ResponseBody
    public UpLoadResult upload(@RequestParam("file") MultipartFile  multipartFile){
        return  OSSService.upload(multipartFile);
    }

    @GetMapping("/download")
    @ResponseBody
    public Result download(@RequestParam("uid") String  uid, HttpServletResponse response){
        return  OSSService.download(uid,response);
    }

    @DeleteMapping("/delete")
    @ResponseBody
    public Result delete(@RequestParam("uid") String  fileName){
        return OSSService.delete(fileName);
    }
}
